package com.adtech.adms.commons.web.listener;

import java.io.IOException;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;
import org.springframework.core.io.ClassPathResource;

import com.adtech.adms.Constants;
import com.adtech.adms.systemlog.LoginLogHelper;
import com.adtech.adms.systemlog.SystemLogHelper;
import com.adtech.core.Settings;
import com.adtech.core.exception.ErrorMessage;

/**
 * 
 * 用于在应用启动时加载系统配置
 * @author Dormin 
 * @since 2011-6-10 
 * 
 * @Copyright (C) AD Tech Workshop All Right Reserved
 */
public class SystemConfigListener implements ServletContextListener {

	private static Logger log = Logger.getLogger(SystemConfigListener.class);
	
	public void contextInitialized(ServletContextEvent sce) {
		LoginLogHelper.init(sce.getServletContext());
		SystemLogHelper.init();
		try {
			Settings.load(new ClassPathResource(Constants.CONFIG_FILE_NAME));
			Settings.load(new ClassPathResource(Constants.CONFIG_SYNC_FILE_NAME));
			Settings.init();
			ErrorMessage.put(com.adtech.adms.commons.ErrorMessage.getMessages());
		} catch (IOException e) {
			log.error("SystemConfigListener.contextInitialized(): IOException", e);
		}
	}

	public void contextDestroyed(ServletContextEvent sce) {

	}

}
